﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Runtime.InteropServices;



public partial class submit : System.Web.UI.Page
{
  
    protected void Page_Load(object sender, EventArgs e)
    {
    }


    //点击支付事件
    protected void sub_Click(object sender, EventArgs e)
    {
        string MerId = this.MerId.Text;//商户号
        string OrdId = Request["OrdId"];//订单号
        string TransAmt = this.TransAmt.Text;//订单金额
        string CuryId = this.CuryId.Text;//货币代码
        string TransDate = Request["TransDate"];//订单日期
        string TransType = this.TransType.Text;//交易类型
        string Priv1 = this.Priv1.Text;//备注
        //准备签名的数据
        string plain = MerId + OrdId + TransAmt + CuryId + TransDate + TransType + Priv1;

        string ChkValue = null;
        Response.Write("MerId:" + MerId);
        ChkValue = SignData.sign(MerId, plain);
        Response.Write("ChkValue:"+ChkValue);
        
        //签名长度256位
        if (ChkValue == null || ChkValue.Length != 256)
        {
            Response.Redirect("error.aspx");
        }
        //保存订单号
        string userName = Session["userName"].ToString();
        string password = Session["password"].ToString();

        string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" + Server.MapPath("./App_Data/paymentInfo.mdb");//创建OleDbConnection对象 
        System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection(ConStr);
        con.Open();

        if (con.State == System.Data.ConnectionState.Open)
        {
            System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand("update record set orderid=" + OrdId + ", orderdate=" + TransDate + " where username=@userName and password=@password", con);
            cmd.Parameters.Add("@userName", userName);
            cmd.Parameters.Add("@password", password);
            int count = cmd.ExecuteNonQuery();

            if (1 != count)
            {
                //保存订单号失败，则跳转到error页面
            }

        }
        con.Close();
        
        Server.Transfer("netpayclient_order_submitmiddle.aspx?ChkValue=" + ChkValue);
    }

   
   
    
}
